<template>
  <!-- 添加或修改请购单对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="驳回原因" prop="reason">
                <el-input v-model="form.reason" type="textarea" placeholder="请输入驳回原因"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" v-if="this.source==0 || this.source==4 || this.source==5 " @click="submitFormToKuguan">驳回到库管</el-button>
      <el-button type="primary" @click="submitForm">驳回到上一步</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "LvdoBohuiJishuForm",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      source: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/lvDo/lvDo/',
        buyReject: '/lvDo/lvDo/buyRejectToJishu',
        submitFormToKuguan: '/lvDo/lvDo/techReject',
      },
    };
  },
  created() {
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        code: null,
        name: null,
        mainId: null,
        nos: null,
        ddDate: null,
        subDate: null,
        type: null,
        ywType: null,
        tax: null,
        customerId: null,
        customerName: null,
        isBuy: null,
        money: null,
        dingjin: null,
        shengyu: null,
        shuie: null,
        counts: null,
        dunwei: null,
        supplierId: null,
        supplierName: null,
        deptId: null,
        deptName: null,
        userId: null,
        userName: null,
        state: null,
        linkman: null,
        linktel: null,
        idcard: null,
        moneycard: null,
        reason: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加请购单";
    },
    /** 修改按钮操作 */
    showJishuBohui(row) {
      this.reset();
      this.form.id = row.id;
      this.source = row.source;
      //this.form.status = status;
      this.open = true;
      this.title = "采购驳回原因";
    },
    submitFormToKuguan() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.submitFormToKuguan, this.form).then(response => {
              this.$modal.msgSuccess("驳回成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.buyReject, this.form).then(response => {
              this.$modal.msgSuccess("驳回成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
